#{extends 'main.html' /}
#{set 'moreScripts'}
	#{script 'jquery.tablesorter.min.js' /}
	<script type="text/javascript">
		$(document).ready(function() { 
			var imovelSelecionado;
			var actionApagar = #{jsAction @Imovels.excluir(':id') /}
			var actionEncerrar = #{jsAction @Imovels.encerrarAnuncio(':id') /}
			
			$('.tt').tooltip();
			$('#lista').tablesorter({
				headers: { 
		            0: { 
		                sorter: false 
		            }
		        } 
			});

			$('.botao-apagar').click(function(){
				imovelSelecionado = $(this).parent().parent().attr('id').replace('imovel-','');
				var nomeimovel = $('.nome-imovel',$(this).parent().parent()).first().text();
				$('#modal-pergunta-apagar').html(i18n('imovel.confirmacao.remover',nomeimovel));
				$('#modal-botao-apagar').attr('href', actionApagar({id:imovelSelecionado}))
				$('#modal-apagar').modal('show');
			});
			
			$('.botao-encerrar').click(function(){
				imovelSelecionado = $(this).parent().parent().attr('id').replace('imovel-','');
				var nomeimovel = $('.nome-imovel',$(this).parent().parent()).first().text();
				$('#modal-pergunta-encerrar').html(i18n('imovel.confirmacao.encerrar',nomeimovel));
				$('#modal-botao-encerrar').attr('href', actionEncerrar({id:imovelSelecionado}))
				$('#modal-encerrar').modal('show');
			});
			
		});
	</script>
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="pt-BR">

  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  

<title>Busca Avançada</title>
</head>
<body>
	
#{/set}
#{set 'moreStyles'}
	#{stylesheet 'tablesorter.css' /}
#{/set}

<h2>Listagem de Imóveis</h2>
<hr style="margin-top: 0" />

#{ifnot imovels}
	<h4>Sua lista de imoveis está vazia.</h4>
#{/ifnot}
#{else}
	<table id="lista" class="table tablesorter table-bordered table-striped">
		<thead>
			<tr>
				<th style="width: 15px;"></th>
				<th>Ref:</th>
			 	<th>Descrição</th>
				<th>Valor</th>
				<th>CEP</th>
				<td style="width: 15px;"></td>
				<th>Destaque</th>
				<td></td>
			</tr>
		</thead>
		<tbody>
			#{list imovels,as:'imovel'}
				<tr id="imovel-${imovel.id}">
					<td><a class="tt botao-alterar" title="Editar" href="@{alterarImovel(imovel.id)}"><i class="icon-edit"></i></a></td>
					<td class="nome-imovel"><a href="@{mostrar(imovel.id)}"></a>Ref: ${imovel.id}</td>
					<td>${imovel.descricao}</td>
					<td>${imovel.valor}</td>
					<td>${imovel.cep}</td>
					<td><a class="tt botao-apagar" title="Apagar" href="#"><i class="icon-trash"></i></a></td>
					#{ifnot imovel.pago}
					<td><a class="tt botao-destaque" title="Destaque seu Cafofo" href="@{locarDestaque(imovel.id)}"><i class="icon-shopping-cart"></i>Locar Destaque</a></td>
					#{/ifnot}
					#{else}
					<td></TD>
					#{/else}
					#{ifnot imovel.status}
					<td><a class="tt" title="Anunciar Novamente" href="@{anunciarNovamente(imovel.id)}"><i class="icon-refresh"></i>Anunciar</a>
					 #{/ifnot}
					 #{else}
					<td><a class="tt botao-encerrar" title="Encerrar Anuncio" href="#"><i class="icon-remove"></i>Encerrar Anuncio</a></td>
					#{/else}
				</tr>
			#{/list}
		</tbody>
	</table>

	<div class="modal fade" id="modal-apagar">
		<div class="modal-header">
			<a class="close" data-dismiss="modal">X</a>
			<h3>Confirmação de exclusão</h3>
		</div>
		<div class="modal-body">
			<p id="modal-pergunta-apagar">Tem certeza que deseja excluir o imóvel?</p>
		</div>
		<div class="modal-footer">
			<a href="#" id="modal-botao-apagar" class="btn btn-danger"><i class="icon-trash icon-white"></i> Apagar</a> 
			<a href="#" data-dismiss="modal" class="btn">Cancelar</a>
		</div>
	</div>
	<div class="modal fade" id="modal-encerrar">
		<div class="modal-header">
			<a class="close" data-dismiss="modal">X</a>
			<h3>Confirmação de encerramento de anuncio</h3>
		</div>
		<div class="modal-body">
			<p id="modal-pergunta-encerrar">Tem certeza que deseja encerrar o anuncio?</p>
		</div>
		<div class="modal-footer">
			<a href="#" id="modal-botao-encerrar" class="btn btn-danger"><i class="icon-remove icon-white"></i> Encerrar anuncio</a> 
			<a href="#" data-dismiss="modal" class="btn">Cancelar</a>
		</div>
	</div>
#{/else}
</body>
</html>